EC-CUBE 2.11.4
[ class tree: EC-CUBE 2.11.4 ] [ index: EC-CUBE 2.11.4 ] [ all elements ]

Source for file SC_GraphPie.php

Documentation is available at SC_GraphPie.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. $ownDir realpath(dirname(__FILE__)) '/';
  25. require_once $ownDir 'SC_GraphBase.php';
  26.  
  27. // 円グラフ生成クラス
  28. class SC_GraphPie extends SC_GraphBase{
  29.     var $cw;
  30.     var $ch;
  31.     var $cz;
  32.     var $cx;
  33.     var $cy;
  34.     var $arrLabel;
  35.     var $arrData;
  36.  
  37.     // コンストラクタ
  38.     function SC_GraphPie($bgw BG_WIDTH$bgh BG_HEIGHT$left PIE_LEFT$top PIE_TOP{
  39.         parent::SC_GraphBase($bgw$bgh$left$top);
  40.         // サイズ設定
  41.         $this->setSize(PIE_WIDTHPIE_HEIGHTPIE_THICK);
  42.         // 位置設定
  43.         $this->setPosition($this->left ($this->cw / 2)$this->top ($this->ch / 2));
  44.     }
  45.  
  46.     // データを360°値に変換する
  47.     function getCircleData($array{
  48.         $total "";
  49.         $new_total "";
  50.         if(!is_array($array)) {
  51.             return;
  52.         }
  53.         $arrRet array();
  54.         foreach($array as $val{
  55.             $total += $val;
  56.         }
  57.         if($total <= 0{
  58.             return;
  59.         }
  60.         $rate 360 $total;
  61.         // ラベル表示用
  62.         $p_rate 100 $total;
  63.         $cnt 0;
  64.         foreach($array as $val{
  65.             $ret round($val $rate);
  66.             $new_total+= $ret;
  67.             $arrRet[$ret;
  68.             // パーセント表示用
  69.             $this->arrLabel[round($val $p_rate" %";
  70.             $cnt++;
  71.         }
  72.         // 合計が360になるように補正しておく
  73.         $arrRet[0-= $new_total 360;
  74.         return $arrRet;
  75.     }
  76.  
  77.     // 円の位置設定を行う
  78.     function setPosition($cx$cy{
  79.         $this->cx = $cx;
  80.         $this->cy = $cy;
  81.     }
  82.  
  83.     // 円のサイズ設定を行う
  84.     function setSize($cw$ch$cz 0{
  85.         $this->cw = $cw;
  86.         $this->ch = $ch;
  87.         $this->cz = $cz;
  88.     }
  89.  
  90.     // 影の描画
  91.     function drawShade({
  92.         $move 1;
  93.         for($i ($this->cy + $this->cz)$i <= ($this->cy + $this->cz + ($this->cz * PIE_SHADE_IMPACT))$i++{
  94.             imagefilledarc($this->image$this->cx + $move$i$this->cw$this->ch0360$this->shade_colorIMG_ARC_PIE);
  95.             $move += 0.5;
  96.         }
  97.     }
  98.  
  99.     // データをセットする
  100.     function setData($arrData{
  101.         $this->arrData = array_values($arrData);
  102.     }
  103.  
  104.     // 円グラフを描画する
  105.     function drawGraph({
  106.         $x $this->cx;
  107.         $y $this->cy;
  108.         $z $this->cz;
  109.         $h $this->ch;
  110.         $w $this->cw;
  111.  
  112.         // データの角度を取得する
  113.         $arrRad $this->getCircleData($this->arrData);
  114.         $rd_max count($arrRad);
  115.  
  116.         // データが存在しない場合
  117.         if($rd_max <= 0{
  118.             return;
  119.         }
  120.  
  121.         // 影の描画
  122.         if($this->shade_on{
  123.             $this->drawShade();
  124.         }
  125.  
  126.         // 色数の取得
  127.         $c_max count($this->arrColor);
  128.         $dc_max count($this->arrDarkColor);
  129.  
  130.         // 側面の描画
  131.         for ($i ($y $z 1)$i >= $y$i--{
  132.             $start 0;
  133.             for($j 0$j $rd_max$j++{
  134.                 // 角度が0度以上の場合のみ側面を描画する。
  135.                 if($arrRad[$j0{
  136.                     $end $start $arrRad[$j];
  137.                     if($start == && $end == 360{
  138.                         // -90~270で指定すると円が描画できないので0~360に指定
  139.                         imagearc($this->image$x$i$w$h0360$this->arrDarkColor[($j $dc_max)]);
  140.                     else {
  141.                         // -90°は12時の位置から開始するように補正している
  142.                         imagearc($this->image$x$i$w$h$start 90$end 90$this->arrDarkColor[($j $dc_max)]);
  143.                     }
  144.                     $start $end;
  145.                 }
  146.             }
  147.         }
  148.         // 底面の描画
  149.         imagearc($this->image$x$y $z$w$h0180 $this->flame_color);
  150.  
  151.         // 上面の描画
  152.         $start 0;
  153.         for($i 0$i $rd_max$i++{
  154.             $end $start $arrRad[$i];
  155.             if($start == && $end == 360{
  156.                 // -90~270で指定すると円が描画できないので0~360に指定
  157.                 imagefilledarc($this->image$x$y$w$h0360$this->arrColor[($i $c_max)]IMG_ARC_PIE);
  158.             else {
  159.                 // -90°は12時の位置から開始するように補正している。
  160.                 imagefilledarc($this->image$x$y$w$h$start 90$end 90$this->arrColor[($i $c_max)]IMG_ARC_PIE);
  161.             }
  162.             $start $end;
  163.         }
  164.  
  165.         // 上面の縁取り
  166.         $start 0;
  167.         for($i 0$i $rd_max$i++{
  168.             $end $start $arrRad[$i];
  169.             if($start == && $end == 360{
  170.                 // -90~270で指定すると円が描画できないので0~360に指定
  171.                 imagearc($this->image$x$y$w$h0360 $this->flame_color);
  172.             }
  173.             // -90°は12時の位置から開始するように補正している。
  174.             imagefilledarc($this->image$x$y$w$h$start 90$end 90$this->flame_colorIMG_ARC_EDGED|IMG_ARC_NOFILL);
  175.             $start $end;
  176.         }
  177.  
  178.         // 側面の縁取り
  179.         imageline($this->image$x ($w 2)$y$x ($w 2)$y $z$this->flame_color);
  180.         imageline($this->image$x ($w 2)$y$x ($w 2)$y $z$this->flame_color);
  181.         $start 0;
  182.         for($i 0$i $rd_max$i++{
  183.             $end $start $arrRad[$i];
  184.             // 前面のみ
  185.             if($end 90 && $end 270{
  186.                 list($ax$ay$this->lfGetArcPos($x$y$w$h$end);
  187.                 // ラインのずれを補正する
  188.                 if($end 180{
  189.                     $ax $ax 1;
  190.                 }
  191.                 imageline($this->image$ax$ay$ax$ay $z$this->flame_color);
  192.             }
  193.             $start $end;
  194.         }
  195.  
  196.         // ラベルの描画
  197.         $this->drawLabel($arrRad);
  198.         // 凡例の描画
  199.         $this->drawLegend(count($this->arrData));
  200.     }
  201.  
  202.     // 円グラフのラベルを描画する
  203.     function drawLabel($arrRad{
  204.         $rd_max count($arrRad);
  205.         $start 0;
  206.         for($i 0$i $rd_max$i++{
  207.             $center $start ($arrRad[$i2);
  208.             $end $start $arrRad[$i];
  209.             list($sx$sy$this->lfGetArcPos($this->cx$this->cy($this->cw / 1.5)($this->ch / 1.5)$center);
  210.             list($ex$ey$this->lfGetArcPos($this->cx$this->cy($this->cw * 1.5)($this->ch * 1.5)$center);
  211.             // 指示線の描画
  212.             imageline($this->image$sx$sy$ex 2$ey PIE_LABEL_UP$this->flame_color);
  213.             $this->setText(FONT_SIZE$ex 10$ey PIE_LABEL_UP FONT_SIZE$this->arrLabel[$i]NULL0true);
  214.             $start $end;
  215.         }
  216.     }
  217. }
  218. ?>

Documentation generated on Fri, 24 Feb 2012 14:02:38 +0900 by Seasoft